#!/bin/bash

echo "🤖 启动小诺机器人图片下载器..."
echo ""

# 检查Python环境
if ! command -v python3 &> /dev/null; then
    echo "❌ 未检测到Python3，请先安装Python3.11+"
    exit 1
fi

# 检查pip
if ! command -v pip &> /dev/null; then
    echo "❌ 未检测到pip，请先安装pip"
    exit 1
fi

# 安装后端依赖
echo "📦 安装后端依赖..."
cd backend
pip install -r requirements.txt

# 启动后端服务
echo "🚀 启动后端服务..."
python main.py &
BACKEND_PID=$!

echo ""
echo "✅ 后端服务已启动 (PID: $BACKEND_PID)"
echo "🌐 后端地址: http://localhost:8000"
echo ""
echo "📱 现在请在浏览器中打开: frontend/index.html"
echo ""
echo "💡 使用说明:"
echo "   1. 在搜索框输入关键词"
echo "   2. 选择需要的图片"
echo "   3. 点击下载按钮"
echo ""
echo "⚠️  按 Ctrl+C 停止服务"

# 等待用户中断
trap "kill $BACKEND_PID 2>/dev/null; exit" INT
wait $BACKEND_PID
